package com.example.service.impl;

import com.example.dao.TeacherDao;
import com.example.entity.Teacher;
import com.example.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherDao teacherDao;

    @Override
    public Teacher getTeacherById(String teacherId) {
        return teacherDao.findById(teacherId);
    }

    @Override
    public List<Teacher> getAllTeachers() {
        return teacherDao.findAll();
    }

    @Override
    public Teacher getTeacherByClassManaged(String classManaged) {
        return teacherDao.findByClassManaged(classManaged);
    }

    @Override
    @Transactional
    public boolean addTeacher(Teacher teacher) {
        return teacherDao.insert(teacher) > 0;
    }

    @Override
    @Transactional
    public boolean updateTeacher(Teacher teacher) {
        return teacherDao.update(teacher) > 0;
    }

    @Override
    @Transactional
    public boolean deleteTeacher(String teacherId) {
        return teacherDao.delete(teacherId) > 0;
    }
} 